<template>
  <div class="brief">
    <div class="avatar">
      <EditImage
        :src="require('@/assets/logo_name.png')"
        width="212"
        height="212"
        :isCircle="true"
        class="img"
      />
      <div class="name" contenteditable="true">小明</div>
      <div class="job" contenteditable="true">高级前端工程师</div>
      <div class="location">
        <div class="location-name" contenteditable="true">中国，广州</div>
      </div>
    </div>
    <div class="info">
      <ul>
        <li>
          <span class="value sex" contenteditable="true">Male</span>
          <br />
          <span class="key sex" contenteditable="true">SEX</span>
        </li>
        <li>
          <span class="value age" contenteditable="true">26</span>
          <br />
          <span class="key age" contenteditable="true">AGE</span>
        </li>
        <li>
          <span class="value degree" contenteditable="true">B.A.</span>
          <br />
          <span class="key degree" contenteditable="true">DEGREE</span>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import EditImage from "@/components/edit-image";
export default {
  name: "Brief",
  components: {
    EditImage
  },
  methods: {
    parseFromJson(json) {
      document.querySelector(".name").innerHTML = json.name;
      document.querySelector(".job").innerHTML = json.job;
      document.querySelector(".location-name").innerHTML = json.location;
      document.querySelector(".sex").innerHTML = json.sex;
      document.querySelector(".age").innerHTML = json.age;
      document.querySelector(".degree").innerHTML = json.degree;
      this.$children.map((item, index) => {
        if (item["parseFromJson"]) {
          item.parseFromJson(json.children[index]);
        }
      });
    },
    toJson() {
      var json = Object.create(null);
      const name = document.querySelector(".name").innerHTML;
      const job = document.querySelector(".job").innerHTML;
      const location = document.querySelector(".location-name").innerHTML;
      const sex = document.querySelector(".sex").innerHTML;
      const age = document.querySelector(".age").innerHTML;
      const degree = document.querySelector(".degree").innerHTML;
      json.c_name = "Brief";
      json.name = name;
      json.job = job;
      json.location = location;
      json.sex = sex;
      json.age = age;
      json.degree = degree;

      var arr = [];
      this.$children.map((item, index) => {
        if (item["toJson"]) {
          arr.push(item.toJson());
        }
      });
      json.children = arr;

      return json;
    }
  }
};
</script>
<style lang="less">
.brief {
  width: 100%;
  height: 630px;
  background-color: #f6f7f7;

  .avatar {
    height: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    & > .img {
      margin-bottom: 45px;
    }

    .name {
      font-size: 32px;
      margin-bottom: 14px;
    }

    .job {
      font-size: 24px;
      color: #555;
      margin-bottom: 16px;
    }

    .location {
      display: flex;
      align-itmes: center;

      .location-name {
        font-size: 20px;
        font-weight: bold;
        margin-left: 10px;
      }
    }
  }

  .info {
    height: 128px;
    width: 100%;
    overflow: hidden;
    border-top: 1px solid #dad8d7;
    border-bottom: 1px solid #dad8d7;
    & > ul {
      height: 100%;
      li:not(:last-child) {
        border-right: 1px solid #dad8d7;
      }

      li {
        float: left;
        width: 33.1%;
        height: 100%;
        overflow: hidden;
        text-align: center;
        padding-top: 25px;
        span {
          display: inline-block;
          margin: 0 auto;
        }
        .value {
          margin-bottom: 10px;
          font-size: 24px;
          font-weight: bold;
        }

        .key {
          font-size: 16px;
          font-weight: bold;
          color: #555;
        }
      }
    }
  }
}
</style>
